<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function compareVersion(version1, version2) {
      let arr1 = version1.split('.')
      let arr2 = version2.split('.')
      console.log(arr1, arr2);


      let forLength = Math.min(arr1.length, arr2.length)
      for (let i = 0; i < forLength; i++) {
        let count = arr1[i] - arr2[i]
        // console.log(count);
        if (count > 0) {
          console.log(1);
          return;
        } else if (count < 0) {
          console.log(-1);
          return;
        } else {
          if (arr1.length > arr2.length) {
            if (arr1[forLength]) {
              return 1
            }
          } else if (arr2.length > arr1.length) {
            if (arr2[forLength]) {
              return -1
            }
          }
          // console.log(0);
          return 0;
        }
      }


    }
    let res = compareVersion('0.21.8.08', '0.20.8')
    console.log(res);
  </script>
</body>

</html>